import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  //获取sessionStorage中的数据

  state : sessionStorage.getItem('state')?JSON.parse(sessionStorage.getItem('state')):{
    user:{
      "userid": null,
      "loginname": null,
      "password": null,
      "userclassify": null,
      "realname": null,
      "idnumber": null,
      "integral": null,
      "phone": null
    }
  },
  mutations: {
    updateUser:function (state,user){
      state.user = user;
    },
    doLogOut:function (state){
      state.user = null
    }
  },
  actions: {
    //异步执行注入对象，通过 this.$store.dispach("asyncUpdateUser",user); 放入数据，方法名，数据对象
    UpdateUser:function (context,user){
      context.commit('updateUser',user);
    },
    doLogOut:function (context){
      context.commit('doLogOut');
    }
  },
  modules: {

  },
  getters: {
    getUser:function (state) {
      return state.user
    }
  }
})


